@extends('layouts.app')

@section('title','ClubLeaderList')

@section('content')
    <div class="container">
        <div class="row">
            <div class="col-md-12">
                <header class="list-header">
                    <section>俱乐部负责人列表</section>
                </header>

                <table class="table table-hover table-striped list-table">
                    <tr class="list-table-tr">
                        <th>负责人名称</th>
                        <th>俱乐部名称</th>
                        <th>电话</th>
                        <th class="text-right">操作</th>
                    </tr>

                    @foreach($leaders as $v)
                        <tr class="content-list">
                            <td>{{ $v->leader_name }}</td>
                            <td>{{ $v->club->club_name }}</td>
                            <td>{{ $v->phone}}></td>
                            <td class="text-right operation">
                                <a href="#" class="delete" data-id="{{ $v->id }}"><i class="fa fa-trash-o fa-lg" aria-hidden="true"></i></a>
                            </td>
                        </tr>
                    @endforeach
                </table>

                {!! $leaders->render() !!}
            </div>
        </div>
    </div>
@endsection

@section('js')
    <script>
        $(document).ready(function () {
            var deleteList = $('.content-list a.delete');

            deleteList.each(function () {
                $(this).click(function () {
                    var id = $(this).data('id'),
                        self = $(this);
                    $.ajaxSetup({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        }
                    });
                    $.ajax({
                        url: 'clubLeader/' + id,
                        type: 'DELETE',
                    }).done(function () {
                        self.closest('tr').remove();
                        $.toaster({ message : '俱乐部负责人删除成功', title : '删除俱乐部负责人', priority : 'success' });
                    });
                });
            });
        });
    </script>
@endsection